<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content=
    "application/xhtml+xml; charset=iso-8859-1" />
    <title>
      About Libtool Archive (.la) files
    </title>
    <link rel="stylesheet" type="text/css" href="../stylesheets/lfs.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.79.1" />
    <link rel="stylesheet" href="../stylesheets/lfs-print.css" type=
    "text/css" media="print" />
  </head>
  <body class="blfs" id="blfs-9.1">
    <div class="navheader">
      <h4>
        Beyond Linux<sup>�</sup> From Scratch <span class="phrase">(System
        V</span> Edition) - Version 9.1
      </h4>
      <h3>
        Chapter&nbsp;2.&nbsp;Important Information
      </h3>
      <ul>
        <li class="prev">
          <a accesskey="p" href="bootscripts.html" title=
          "BLFS Boot Scripts">Prev</a>
          <p>
            BLFS Boot Scripts
          </p>
        </li>
        <li class="next">
          <a accesskey="n" href="libraries.html" title=
          "Libraries: Static or shared?">Next</a>
          <p>
            Libraries: Static or shared?
          </p>
        </li>
        <li class="up">
          <a accesskey="u" href="important.html" title=
          "Chapter&nbsp;2.&nbsp;Important Information">Up</a>
        </li>
        <li class="home">
          <a accesskey="h" href="../index.html" title=
          "Beyond Linux� From Scratch     (System V Edition) - Version 9.1">Home</a>
        </li>
      </ul>
    </div>
    <div class="sect1" lang="en" xml:lang="en">
      <h1 class="sect1">
        <a id="la-files" name="la-files"></a>About Libtool Archive (.la)
        files
      </h1>
      <div class="package" lang="en" xml:lang="en">
        <h2 class="sect2">
          Files with a .la extention
        </h2>
        <p>
          In LFS we installed a package, libtool, that is used by many
          packages to build on a variety of Unix platforms. This includes
          platforms such as AIX, Solaris, IRIX, HP-UX, and Cygwin as well as
          Linux. The origins of this tool are quite dated. It was intended to
          manage libraries on systems with less advanced capabilities than a
          modern Linux system.
        </p>
        <p>
          On a Linux system, libtool specific files are generally unneeded.
          Normally libraries are specified in the build process during the
          link phase. Since a linux system uses the <a class="ulink" href=
          "https://en.wikipedia.org/wiki/Executable_and_Linkable_Format">Executable
          and Linkable Format (ELF)</a> for executables and libraries,
          information needed to complete the task is embedded in the files.
          At run time the program loader can query the appropriate files and
          properly load and execute the program.
        </p>
        <p>
          The problem is that libtool usually creates one or more text files
          for package libraries called libtool archives. These small files
          have a ".la" extention and contain information that is similar to
          that embedded in the libraries. When building a package that uses
          libtool, the process automatically looks for these files. If a
          package is updated and no longer uses the .la file, then the build
          process can break.
        </p>
        <p>
          The solution is to remove the .la files. However there is a catch.
          Some packages, such as <a class="xref" href=
          "../general/imagemagick.html" title=
          "ImageMagick-7.0.9-23">ImageMagick-7.0.9-23</a>, use a libtool
          function, lt_dlopen, to load libraries as needed during execution
          and resolve their dependencies at run time. In this case, the .la
          files should remain.
        </p>
        <p>
          The script below, removes all unneeded .la files and saves them in
          a directory, /var/local/la-files by default, not in the normal
          library path. It also searches all pkg-config files (.pc) for
          embedded references to .la files and fixes them to be conventional
          library references needed when an application or library is built.
          It can be run as needed to clean up the directories that may be
          causing problems.
        </p>
        <pre class="root">
<kbd class="command">cat &gt; /usr/sbin/remove-la-files.sh &lt;&lt; "EOF"
<code class="literal">#!/bin/bash

# /usr/sbin/remove-la-files.sh
# Written for Beyond Linux From Scratch
# by Bruce Dubbs &lt;bdubbs@linuxfromscratch.org&gt;

# Make sure we are running with root privs
if test "${EUID}" -ne 0; then
    echo "Error: $(basename ${0}) must be run as the root user! Exiting..."
    exit 1
fi

# Make sure PKG_CONFIG_PATH is set if discarded by sudo
source /etc/profile

OLD_LA_DIR=/var/local/la-files

mkdir -p $OLD_LA_DIR

# Only search directories in /opt, but not symlinks to directories
OPTDIRS=$(find /opt -mindepth 1 -maxdepth 1 -type d)

# Move any found .la files to a directory out of the way
find /usr/lib $OPTDIRS -name "*.la" ! -path "/usr/lib/ImageMagick*" \
  -exec mv -fv {} $OLD_LA_DIR \;
###############

# Fix any .pc files that may have .la references

STD_PC_PATH='/usr/lib/pkgconfig 
             /usr/share/pkgconfig 
             /usr/local/lib/pkgconfig 
             /usr/local/share/pkgconfig'

# For each directory that can have .pc files
for d in $(echo $PKG_CONFIG_PATH | tr : ' ') $STD_PC_PATH; do

  # For each pc file
  for pc in $d/*.pc ; do
    if [ $pc == "$d/*.pc" ]; then continue; fi

    # Check each word in a line with a .la reference
    for word in $(grep '\.la' $pc); do
      if $(echo $word | grep -q '.la$' ); then
        mkdir -p $d/la-backup
        cp -fv  $pc $d/la-backup

        basename=$(basename $word )
        libref=$(echo $basename|sed -e 's/^lib/-l/' -e 's/\.la$//')
           
        # Fix the .pc file
        sed -i "s:$word:$libref:" $pc
      fi
    done
  done
done

EOF

chmod +x /usr/sbin/remove-la-files.sh</code></kbd>
</pre>
        <p class="usernotes">
          User Notes: <a class="ulink" href=
          "http://wiki.linuxfromscratch.org/blfs/wiki/la-files">http://wiki.linuxfromscratch.org/blfs/wiki/la-files</a>
        </p>
      </div>
      <p class="updated">
        Last updated on 2017-12-23 07:56:03 -0800
      </p>
    </div>
    <div class="navfooter">
      <ul>
        <li class="prev">
          <a accesskey="p" href="bootscripts.html" title=
          "BLFS Boot Scripts">Prev</a>
          <p>
            BLFS Boot Scripts
          </p>
        </li>
        <li class="next">
          <a accesskey="n" href="libraries.html" title=
          "Libraries: Static or shared?">Next</a>
          <p>
            Libraries: Static or shared?
          </p>
        </li>
        <li class="up">
          <a accesskey="u" href="important.html" title=
          "Chapter&nbsp;2.&nbsp;Important Information">Up</a>
        </li>
        <li class="home">
          <a accesskey="h" href="../index.html" title=
          "Beyond Linux� From Scratch     (System V Edition) - Version 9.1">Home</a>
        </li>
      </ul>
    </div>
  </body>
</html>
